<template>
  <div>
    <p class="pinformation">样品统计</p>
    <el-form :model="form" ref="formRef" label-width="80">
      <el-row>
        <el-form-item label="样品编号×检测项目总数：" label-width="170">
          {{ form.sampleCodeCountJcxm }}
        </el-form-item>
        <el-form-item style="margin-left: 10px" label="已填报数：">
          {{ form.writeCount }}
        </el-form-item>
        <el-form-item style="margin-left: 10px" label="未填报数：">
          {{ form.notWriteCount }}
        </el-form-item>
        <el-form-item
          style="margin-left: 10px"
          label="已填报原始记录数："
          label-width="130"
        >
          {{ form.labWriteCount }}
        </el-form-item>
        <el-form-item
          style="margin-left: 10px"
          label="未审核原始记录数："
          label-width="130"
        >
          {{ form.notApproveCount }}
        </el-form-item>
      </el-row>
    </el-form>
    <p class="pinformation">实验室原始记录搜索</p>
    <el-form ref="queryRef" label-width="80" :model="queryParams">
      <el-row>
        <el-col :span="5">
          <el-form-item label="方法编号：" prop="methodCode" label-width="80">
            <el-input
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
              placeholder="请输入"
              v-model="queryParams.methodCode"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="检测项目：" prop="jcxmName" label-width="80">
            <el-input
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
              placeholder="请输入检测项目"
              v-model="queryParams.jcxmName"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-row style="justify-content: center">
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="resetBtn" @click="resetQuery">重置</el-button>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <p class="pinformation">实验室原始记录列表</p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table border :data="tableData" ref="dataTableRef" v-loading="loading">
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="方法编号"
        prop="methodCode"
        width="140"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="方法名称"
        prop="methodName"
      >
        <template #default="scope">
          <span v-html="proxy.getSupAndSub(scope.row.methodName)"></span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="样品数量"
        prop="sampleCount"
        width="85"
      />
      <el-table-column align="center" show-overflow-tooltip label="检测项目">
        <template #default="scope">
          <span v-html="proxy.getSupAndSub(scope.row.jcxmNames)"></span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="填报人"
        prop="createUserName"
        width="85"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="填报时间"
        prop="writeTime"
        width="140"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="复核人"
        prop="reviewName"
        width="80"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="复核时间"
        prop="reviewTime"
        width="140"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="审核人"
        prop="approveName"
        width="80"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="审核时间"
        prop="approveTime"
        width="140"
      />
      <el-table-column
        show-overflow-tooltip
        label="操作"
        align="center"
        width="70"
        fixed="right"
      >
        <template #default="scope">
          <el-button link type="success" @click="handleWrite(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <newBuiltTab ref="writeRef"></newBuiltTab>
  </div>
</template>

<script setup>
import { getSysysjlFrom, getSysysjlList } from "@/api/taskProgressDetails/index";
import newBuiltTab from "@/views/lab/labMethod/newBuilt.vue";

const { proxy } = getCurrentInstance();
const form = ref({});
const queryParams = ref({ pageNum: 1, pageSize: 10 });
const tableData = ref([]);
const total = ref(0);
const projectId = ref("");
const loading = ref(false);
const heightParams = ref([{ tableName: "data", bottomHeight: 21 }]);
const writeRef = ref(null);

function getForm(val) {
  projectId.value = val;
  queryParams.value.projectId = val;
  getSysysjlFrom(val).then((res) => {
    form.value = res.data;
  });
  getList();
}

function getList() {
  loading.value = true;
  getSysysjlList(queryParams.value).then((res) => {
    tableData.value = res.rows;
    total.value = res.total;
    loading.value = false;
  });
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

defineExpose({
  getForm,
});

function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

function handleWrite(row) {
  writeRef.value.open = true;
  writeRef.value.title = "数据填报";
  writeRef.value.lMId = row.lMId;
  writeRef.value.myId = row.lMId;
  nextTick(() => {
    writeRef.value.tabsView();
  });
}
watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "data", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "data", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);
</script>

<style></style>
